package com.uniview.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.uniview.base.BaseDao;
import com.uniview.entity.po.Role;
import com.uniview.entity.vo.Pager;
import com.uniview.entity.vo.QueryBuilder;

/**
 * 角色Dao类
 * @author Leiqingtian
 *
 */
@Repository("roleDao")
public class RoleDao extends BaseDao<Role> {

	/**
	 * 保存角色信息
	 * @param role
	 * @return
	 * @throws Exception
	 */
	public int saveRole(Role role) throws Exception{
		return (int)this.save(role);
	}
	
	/**
	 * 修改角色信息
	 * @param role
	 * @return
	 * @throws Exception
	 */
	public boolean updateRole(Role role) throws Exception{
		return this.update(role);
	}
	
	/**
	 * 删除角色信息
	 * @param rId
	 * @return
	 * @throws Exception
	 */
	public boolean deleteRole(int rId) throws Exception{
		return this.deleteById(rId);
	}
	
	/**
	 * 查找所有的角色信息
	 * @return
	 * @throws Exception
	 */
	public List<Role> findAllRole() throws Exception{
		return this.findBySql("select * from sd_role order by id desc");
	}
	
	/**
	 * 分页查找角色信息
	 * @param queryBuilder
	 * @param pageNo
	 * @param pageSize
	 * @return
	 * @throws Exception
	 */
	public Pager<Role> findRoleByPage(QueryBuilder queryBuilder,int pageNo,int pageSize) throws Exception{
		return this.findPagerByQueryBuilder(queryBuilder, pageNo, pageSize);
	}
	
	/**
	 * 获取角色的记录总数
	 * @return
	 * @throws Exception
	 */
	public Long getTotalRow() throws Exception{
		return this.findTotalRow();
	}
	
	/**
	 * 根据id获取角色信息
	 * @param roleId
	 * @return
	 * @throws Exception
	 */
	public Role findRoleById(int roleId) throws Exception{
		return this.find(roleId);
	}
}
